﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ArduinoSketch.Core
{
    public abstract class Uploader
    {
        public Uploader() { }


        #region Runer Process
        protected virtual string RunProcess(string filename, string arguments)
        {
            System.IO.StreamReader sr;
            Process builder = new Process();

            builder.StartInfo.RedirectStandardOutput = true;
            builder.StartInfo.RedirectStandardError = true;
            builder.StartInfo.UseShellExecute = false;
            builder.StartInfo.CreateNoWindow = true;
            builder.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            builder.StartInfo.FileName = filename;
            builder.StartInfo.Arguments = arguments;
            builder.Start();
            builder.WaitForExit();

            sr = builder.StandardOutput;
            string _strOutput = sr.ReadToEnd();
            if (!string.IsNullOrEmpty(_strOutput))
                Console.Out.WriteLine(_strOutput);

            sr = builder.StandardError;

            return sr.ReadToEnd();
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        protected abstract string executeUploadCommand(string filename, IEnumerable<string> param);
    }
}
